package zb.lambda;

import java.util.Arrays;
import java.util.Random;

/**
 * @author wzby
 * @Date: 2022/8/5 21:13
 */
public class Lam4 {
    public static void main(String[] args) {
        //实现字符串集合排序（字母顺序，字符串长度）
        String [] s = {"java","javase","css","go","python"};
        System.out.println(Arrays.toString(s));
        //升序 Arrays工具类.sort（）静态方法
        Arrays.sort(s);
        System.out.println(Arrays.toString(s));

        //降序
        Arrays.sort(s,(a,b) -> b.compareTo(a));
        System.out.println(Arrays.toString(s));

        //乱序
        Random rand = new Random();
        Arrays.sort(s,(a,b) -> rand.nextBoolean() ? 1: -1);
        System.out.println(Arrays.toString(s));

        //根据字母个数
        Arrays.sort(s,(a,b) -> a.length()-b.length());
        System.out.println(Arrays.toString(s));

        //乱序
        Arrays.sort(s,(a,b) -> Math.random() > .5 ? 1: -1);
        System.out.println(Arrays.toString(s));
    }
}
